﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;

namespace Engine.Sgml {
    /// <summary>
    /// Exposes common HTTP header values sent to Internet resource as properties.
    /// </summary>
    public class HttpRequestSettings {
        /// <summary>
        /// Gets the default method for the request.
        /// </summary>
        /// <value>By default return 'GET' method.</value>
        public static string DefaultMethod { get { return "GET"; } }
        /// <summary>
        /// Gets the default time-out value in milliseconds.
        /// </summary>
        /// <value>By default return '100000' milliseconds.</value>
        public static int DefaultTimeout { get { return 100000; } }
        /// <summary>
        /// Gets the default value of the User-agent HTTP header.
        /// </summary>
        /// <value>By default return 'Mozilla/4.0 (compatible;);'.</value>
        public static string DefaultUserAgent { get { return "Mozilla/4.0 (compatible;);"; } }

        /// <summary>
        /// Gets the default settings of the web request.
        /// </summary>
        public static HttpRequestSettings DefaultSettings { get; private set; }

        static HttpRequestSettings() {
            DefaultSettings = new HttpRequestSettings();
            }

        /// <summary>
        /// Initialize a new instance of the WebRequestSettings class.
        /// </summary>
        public HttpRequestSettings() {
            timeout = DefaultTimeout;
            method = DefaultMethod;
            UserAgent = DefaultUserAgent;
            }

        /// <summary>
        /// Gets of sets the raw user agent string of the client browser.
        /// </summary>
        public string UserAgent { get; set; }

        /// <summary>
        /// Gets or sets the cookies associated with web request.
        /// </summary>
        public CookieContainer CookieContainer { get; set; }

        /// <summary>
        /// Gets or sets the web proxy to use to access the Internet resource.
        /// </summary>
        public IWebProxy WebProxy { get; set; }

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private int timeout;
        /// <summary>
        /// Gets or sets the length of time, in milliseconds, before the request times out.
        /// </summary>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        public int Timeout {
            get { return timeout; }
            set {
                if (value < 0 && value != System.Threading.Timeout.Infinite)
                    throw new ArgumentOutOfRangeException("value");
                timeout = value;
                }
            }

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private string method;
        /// <summary>
        /// Gets or sets the protocol method to use in web request.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">If value is null.</exception>
        public string Method {
            get { return method; }
            set {
                Guard.ArgumentNotNull(value, "value");
                method = value;
                }
            }

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private string contentType;
        /// <summary>
        /// Gets or sets the content type of the request data.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">If value is null.</exception>
        public string ContentType {
            get { return contentType; }
            set {
                Guard.ArgumentNotNull(value, "value");
                contentType = value;
                }
            }

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private string content;
        /// <summary>
        /// Gets or sets the value that must be written to the request stream to send as
        /// HTTP header with web request.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">If value is null</exception>
        public string Content {
            get { return content; }
            set {
                Guard.ArgumentNotNull(content, "content");
                content = value;
                }
            }
        }
    }
